﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class CalendarQuery_EmpCalendarShow : System.Web.UI.Page {
    private string userLoginName;

    protected void Page_Load(object sender, EventArgs e) {
        if(!Page.IsPostBack) {
            if(Request.QueryString.Get("u_ln") != null) {
                this.TxtStart.Attributes.Add("onfocus", "calendar()");
                this.TxtEnd.Attributes.Add("onfocus", "calendar()");
                userLoginName = Request.QueryString.Get("u_ln");
                MakeList();
                ViewState["u_ln"] = userLoginName;
            }
        }
    }

    protected void MakeList() {
        UserDiarytbService udService = new UserDiarytbService();
        List<UserDiary> list = udService.findByUserLoginName(userLoginName);
        DataList_DataTable(list);
    }

    protected void DataList_DataTable(List<UserDiary> list) {
        if(list != null && list.Count > 0) {
            DataTable dt = new DataTable();
            dt.Columns.Add("UserDiaryId", typeof(string));
            dt.Columns.Add("UserDiaryCreateTime", typeof(string));
            dt.Columns.Add("UserDiaryTitle", typeof(string));
            foreach(UserDiary ud in list) {
                DataRow dr = dt.NewRow();
                dr["UserDiaryId"] = ud.DiaryId.ToString();
                dr["UserDiaryCreateTime"] = ud.RegisterTime.ToString();
                dr["UserDiaryTitle"] = ud.DiaryTitle;
                dt.Rows.Add(dr);
            }
            this.DataList1.DataSource = dt.DefaultView;
        } else {
            this.DataList1.DataSource = null;
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('无工作计划！');", true);
        }
        DataList1.DataBind();
    }

    protected void BtnFind_Click(object sender, EventArgs e) {
        User curLoginUser = (User) Session["user"];
        string txtStart = Request.Form.Get(this.TxtStart.ClientID);
        string txtEnd = Request.Form.Get(this.TxtEnd.ClientID);
        string txtTitleOne = Request.Form.Get(this.TxtTitleOne.ClientID);
        string txtTitleTwo = Request.Form.Get(this.TxtTitleTwo.ClientID);
        string txtContentOne = Request.Form.Get(this.TxtContentOne.ClientID);
        string txtContentTwo = Request.Form.Get(this.TxtContentTwo.ClientID);
        if(!"".Equals(txtStart.Trim()) || !"".Equals(txtEnd.Trim()) || !"".Equals(txtTitleOne.Trim()) || !"".Equals(txtTitleTwo.Trim())
            || !"".Equals(txtContentOne.Trim()) || !"".Equals(txtContentTwo.Trim())) {
            UserDiarytbService udServicd = new UserDiarytbService();
            List<UserDiary> list = udServicd.findUserDiaryManager(txtStart, txtEnd, txtTitleOne, txtTitleTwo, txtContentOne, txtContentTwo, curLoginUser.LoginName);
            this.DataList_DataTable(list);
        }
    }
    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e) {
        if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) {
            string ud_id = ((HyperLink) e.Item.FindControl("HylTitle")).Attributes["ud_id"];
            ((HyperLink) e.Item.FindControl("HylTitle")).NavigateUrl = "DiaryContentShow.aspx?ud_id=" + ud_id;
        }
    }
}
